package com.atguigu.gulimallcart.config;

import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @author houChen
 * @date 2021/12/31 7:34
 * @Description:
 */
@Configuration
public class GulimallSessionConfig {

    /**
     * @Description:  指定cookie的作用域,访问所有的子域和父域的域名时，都能携带这个cookie
     * @author  houChen
     * @date  2021/12/31 7:39
     */
    @Bean
    public CookieSerializer cookieSerializer(){
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
        cookieSerializer.setDomainName("gulimall.com");
        cookieSerializer.setCookieName("GULISESSION");
        return cookieSerializer;
    }


    /**
     * @Description:  redis的序列化器
     * @author  houChen
     * @date  2021/12/31 7:41
     */
    @Bean
    public RedisSerializer<Object> SpringSessionDefaultRedisSerializer(){
        return  new GenericFastJsonRedisSerializer();
    }
}